package com.example.padtestproject;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

public class SampleFragment extends Fragment {

    private static final String ARG_SONG_NAME = "songName";

    public static SampleFragment newInstance(String songName) {
        SampleFragment fragment = new SampleFragment();
        Bundle args = new Bundle();
        args.putString(ARG_SONG_NAME, songName);
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_sample, container, false);

        TextView textView = view.findViewById(R.id.textView);

        // 接收传递的数据
        if (getArguments() != null) {
            String songName = getArguments().getString(ARG_SONG_NAME);
            textView.setText(songName != null ? "Now Playing: " + songName : "No Song Selected");
        }

        return view;
    }
}